<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:replace="fragments/custom_base::commonHead"></th:block>
    <th:block th:replace="fragments/custom_link::home-css"></th:block>
    <th:block th:replace="fragments/custom_link::home-js"></th:block>
    <style>

    </style>
</head>
<body>
<th:block th:replace="fragments/custom_base::commonNav"></th:block>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md-offset3 layui-col-sm-offset3 layui-col-md6 layui-col-sm6">
            <div class="custom-form">
                <div class="title">
                    <h2> 登录 </h2>
                </div>
                <div class="custom-form-body">
                    <form class="layui-form" action="your-login-action-url" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号：</label>
                            <div class="layui-input-block">
                                <input type="text" name="phone" required lay-verify="required" placeholder="注册时预留的手机号~" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码：</label>
                            <div class="layui-input-block">
                                <input type="password" name="password" required lay-verify="required" placeholder="注册时的账号密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">验证码：</label>
                            <div class="layui-input-block verify">
                                <input type="text" name="code" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input verify-input">
                                <img src="/captcha" alt="验证码" onclick="this.src='/captcha?time='+new Date().getTime()" style="width: 150px;height: 40px;cursor: pointer;">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="login">登录</button>
                                <a href="/users/forget" class="layui-btn layui-btn-primary">找回密码</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:replace="fragments/custom_base :: commonFooter"></th:block>
</body>
<th:block th:replace="fragments/custom_base :: commonScript"></th:block>
<script type="application/javascript">
    layui.use(['form'], function(){
        var form = layui.form; //获取form模块

        //监听提交
        form.on('submit(login)', function(data){
            //执行登录请求的逻辑，这里只是一个示例
            console.log(data.field); //当前容器的全部表单字段，键值对形式：{name: value}
            $.ajax({
                url: '/users/login_request',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.status === 200) {
                        layer.msg(result.message, {icon: 1, time: 1000}, function () {
                            window.location.href = "/users/info";
                        });
                    } else {
                        layer.msg(result.message, {icon: 2, time: 1000});
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</html>